package com.wink_172.library.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 https://blog.csdn.net/u010126792/article/details/85237085?ops_request_misc=&request_id=&biz_id=102&utm_term=LinearGradient&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-85237085.pc_search_result_hbase_insert&spm=1018.2226.3001.4187
 * 自定义颜色渐变
 * 可用于字体或其他
 * */
public class CustomerLinearGradient extends View {
    public CustomerLinearGradient(Context context) {
        super(context);
    }

    public CustomerLinearGradient(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomerLinearGradient(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.FILL);


        //(x0,y0)：渐变起始点坐标
        //(x1,y1):渐变结束点坐标
        //color0:渐变开始点颜色,16进制的颜色表示，必须要带有透明度
        //color1:渐变结束颜色
        //colors:渐变数组
        android.graphics.LinearGradient linearGradient = new android.graphics.LinearGradient(
                0,0,0,getHeight(),
                getResources().getColor(com.wink_172.library.R.color.peach02),
                getResources().getColor(com.wink_172.library.R.color.peach01),
                Shader.TileMode.CLAMP);
        mPaint.setShader(linearGradient);
        canvas.drawRect(0,0,getWidth(),getHeight(),mPaint);

    }
}
